package cn.edu.scau.cmi.wujiaxian.exercise10;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;


public class Example10_12 {
	
	public static void main(String[] args) {
		String command = "渡江总攻时间是4月22日晚10点";
		EncryptAndDecrypt encryptAndDecrypt = new EncryptAndDecrypt();
		String password = "Tiger";
		String secret = encryptAndDecrypt.encrypt(command, password);
		File file = new File("secret.txt");
		try {
			FileOutputStream fos = new FileOutputStream(file);
			DataOutputStream dos = new DataOutputStream(fos);
			dos.writeUTF(secret);
			System.out.println(secret);
			dos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			FileInputStream fos = new FileInputStream(file);
			DataInputStream dis = new DataInputStream(fos);
			String s = dis.readUTF();
			String mingwen = encryptAndDecrypt.decrypt(s, password);
			System.out.println(mingwen);
			dis.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
}
